package primitiveTests;
import primitives.graph.Node;
import primitives.cluster.ClusterLeaf;
import java.util.HashSet;
import java.util.Set;

import primitives.*;
import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class ClusterTest {
	ClusterLeaf c;
	Node outsideIn;
	Node outsideOut;
	Node a,b;
	@Before
	public void setUp() throws Exception {
		c = new ClusterLeaf();
		a = new Node("a");
		b = new Node("b");
		outsideIn = new Node("outside -> in ");
		outsideOut = new Node("cluster -> outside");
		c.addNode(a);
		c.addNode(b);
		outsideIn.connect(a," a ");
		b.connect(outsideOut, " b ");
	}
	@Test
	public void testGetNodes() {
		Set<Node> n = c.getNodes();
		for(Node node: n){
			assertFalse(node != a && node != b);
		}
		n.remove(a);
		assertTrue(c.contains(a));
	}

/*
	@Test
	public void testClusterSetOfNode() {
		HashSet<Node> hs = new HashSet<Node>();
		hs.add(a); hs.add(b);
		c = new ClusterLeaf(hs);
		assertTrue(c.getNodes().contains(a));
		assertTrue(c.contains(a));
		hs.remove(a);
		hs.remove(b);
		assertFalse(c.getNodes().isEmpty());
	}
*/
	@Test
	public void testEncapsulates() {
		assertFalse(c.encapsulates());
	}

	@Test
	public void testAddNode() {
		Node n = new Node("c");
		c.addNode(n);
		assertTrue(c.contains(n));
	}

	@Test
	public void testRemoveNode() {
		Node n = new Node("c");
		c.addNode(n);
		assertTrue(c.contains(n));

		assertFalse(c.contains(n));
	}

	@Test
	public void testContains() {
		Node n = new Node ("c");
		assertFalse(c.contains(n));
		assertTrue(c.contains(a));
		assertTrue(c.contains(b));
		c.addNode(n);
		assertTrue(c.contains(n));
	}

	@Test
	public void testConnectivityTo() {
		assertTrue(c.connectivityTo(outsideOut));
	}

	@Test
	public void testConnectivityFrom() {
		assertTrue(c.connectivityFrom(outsideIn));
	}

	@Test
	public void testConnectivityBidir() {
		assertTrue(c.connectivityBidir(outsideIn));
		assertTrue(c.connectivityBidir(outsideOut));
	}

	@Test
	public void testGetCluster() {
		assertEquals(c.getCluster(), c);
	}

}
